package com.tc.utils.image.table;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Frederic.Tang on 2018/8/23.
 */
public class TableRow {
    Map<Integer,TableCell> cells;
    //列数
    int col;
    int w;
    int h;
    int x;
    int y;
    int[] cellw;
    int nextI;
    protected TableRow(int col) {
        this.col = col;
        cells =  new HashMap<>();
        for(int i=0;i<col;i++){
            cells.put(i,new TableCell(""));
        }
        cellw =new int[col];
    }

    public String getCellText(int i) throws Exception {
        if(i<0||i>=col){
            throw new Exception("out of range") ;
        }else
        {
            return cells.get(i).getText();
        }
    }
    public TableRow setCellText(int i, String text) throws Exception {
        if(i<0||i>=col){
            throw new Exception("out of range") ;
        }
        cells.get(i).setText(text);
        nextI=i+1;
        return this;
    }

    public TableRow setCellText(String text) throws Exception {
        if(nextI<0||nextI>=col){
            throw new Exception("out of range") ;
        }
        cells.get(nextI).setText(text);
        nextI=nextI+1;
        return this;
    }

    public void calc(Graphics2D g) {
        for(int i=0;i<col;i++){
            TableCell cell=this.cells.get(i);
            cell.calc(g);
            cellw[i]=cell.w;
        }

    }
}
